package Bill.app.client;

import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.*;
import javax.swing.*;

class ThreadTchat1 extends Thread
{

    ThreadTchat1(BufferedReader lecture, JList liste, JLabel info, String dest, String Etat, String Etatici, Hashtable Discussion, 
            DefaultListModel model)
    {
        this.lecture = null;
        this.liste = null;
        this.info = null;
        this.dest = "";
        this.Etat = null;
        this.Etatici = null;
        this.model = null;
        this.Discussion = null;
        this.dest = dest;
        this.lecture = lecture;
        this.liste = liste;
        this.info = info;
        this.Etat = Etat;
        this.Etatici = Etatici;
        this.Discussion = Discussion;
        this.model = model;
        start();
    }

    public void run()
    {
        do
        {
            String mes;
            
                mes = "";
                try
                {
                    mes = lecture.readLine();
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
                if(mes.compareToIgnoreCase("800") == 0)
                {
                    info.setText((new StringBuilder(String.valueOf(dest))).append(" est en train d'\351crire...").toString());
                    info.setVisible(true);
                } else
                if(mes.compareToIgnoreCase("900") == 0)
                    info.setVisible(false);
                if(mes.compareToIgnoreCase("END") == 0)
                    stop();
                if(mes.compareToIgnoreCase("null") != 0 && mes.compareToIgnoreCase("800") != 0 && mes.compareToIgnoreCase("END") != 0 && mes.compareToIgnoreCase("WIZZ") != 0 && mes.compareToIgnoreCase("900") != 0)
                { try{
                    StringTokenizer tt = new StringTokenizer(mes, "=");//expediteur:destinataire:coul=message
                    String coul = tt.nextToken();
                    String mess = tt.nextToken();
                    JLabel label = new JLabel((new StringBuilder("<html><font color=#")).append(coul).append(">").append(dest).append(":").append(mess).append("</font></html>").toString());
                    label.setToolTipText((new StringBuilder()).append((new Date()).toLocaleString()).toString());
                    label.setFont(new Font("Serif", 1, 15));
                    model.addElement(label);
                    liste.setModel(model);
                }catch(Exception e){
                	
                }
                }
            if(mes.compareToIgnoreCase("WIZZ") == 0);
            new Wiz((Chat)Discussion.get(dest), 30, 2);
        } while(true);
    }

    BufferedReader lecture;
    JList liste;
    JLabel info;
    String dest;
    String Etat;
    String Etatici;
    DefaultListModel model;
    Hashtable Discussion;
}
